package 题目集.贪心.排序模拟;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;

public class F删除整数_手写堆 {

    static long[] arr;
    static boolean[] del;   //是否被删除
    static int n, k;
    static int maxN = 5 * (int) (1e5) + 1;
    static int[][] index = new int[maxN][2];  //记录每个位置的左侧和右侧

    public static void main(String[] args) {
        Reader sc = new Reader();
        n = sc.nextInt();
        k = sc.nextInt();
        arr = new long[n];
        del = new boolean[n];
        PriorityQueue queue = new PriorityQueue(n);
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
            queue.add(i, arr[i]);
            index[i][0] = i - 1;
            index[i][1] = i + 1;
        }
        for (int i = 0; i < k; i++) {//k
            long[] pop = queue.pop();
            int id = (int) pop[1];
            del[id] = true;
            int l = index[id][0];
            int r = index[id][1];
            if (l != -1 && !del[l]) {
                index[l][1] = r;
                arr[l] += pop[0];
                queue.update(l, arr[l]);
            }
            if (r != n && !del[r]) {
                index[r][0] = l;
                arr[r] += pop[0];
                queue.update(r, arr[r]);
            }
        }
        for (int i = 0; i < del.length; i++) {
            if (!del[i]) {
                System.out.print(arr[i] + " ");
            }
        }
        System.out.println();
    }

    static class PriorityQueue {
        long[] node;
        int[] heapIndex;     //存储每个数据对应在堆中的位置
        int[] srcIndex;      //存储堆中的数据对应的原始下标
        int capacity;
        int size;

        public PriorityQueue(int capacity) {
            this.capacity = capacity + 1;
            node = new long[this.capacity];
            heapIndex = new int[this.capacity];
            srcIndex = new int[this.capacity];
        }

        public void add(int i, long v) {
            size++;
            heapIndex[i] = size;
            srcIndex[size] = i;
            node[size] = v;
            up(size);
        }

        public void update(int i, long v) {
            long oldV = node[heapIndex[i]];
            node[heapIndex[i]] = v;
            if (v < oldV) {
                up(heapIndex[i]);
            } else {
                down(heapIndex[i]);
            }
        }

        /**
         * 返回值和下标
         * @return
         */
        public long[] pop() {
            long[] info = new long[]{node[1], srcIndex[1]};
            swap(1, size--);
            down(1);
            return info;
        }

        private void down(int i) {
            int l = i << 1;
            while (l <= size) {
                int r = l | 1;
                int c = r <= size && compare(r, l) == -1 ? r : l;
                if (compare(i, c)<0) return;
                swap(c, i);
                i = c;
                l = i << 1;
            }
        }

        /**
         * @param i：堆中的下标
         */
        private void up(int i) {
            int p = i >> 1;
            while (compare(i, p) < 0) {
                swap(i, p);
                i = p;
                p = i >> 1;
            }
        }

        /**
         * 交换堆中a,b位置的元素
         */
        public void swap(int a, int b) {
            long temp = srcIndex[a];
            srcIndex[a] = srcIndex[b];
            srcIndex[b] = (int) temp;
            temp = node[a];
            node[a] = node[b];
            node[b] = temp;
            heapIndex[srcIndex[a]] = a;
            heapIndex[srcIndex[b]] = b;
        }

        /**
         * a位置的元素与b位置的大小情况
         */
        public int compare(int a, int b) {
            if (node[a] == node[b]) {
                return srcIndex[a] - srcIndex[b];
            }
            return node[a] < node[b] ? -1 : 1;
        }
    }
    static class Reader {
        static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

        public static int nextInt() {
            try {
                in.nextToken();
            } catch (Exception ignored) {}
            return (int) in.nval;
        }
    }
}
